<?php
/*
 * Created on Oct 14, 2008
 *
 * Login page.
 */
require_once("../../server/dbconnect.php");

session_start();

$error = "";

function errorHandler($errno, $errstr, $errfile, $errline) {
	// trap error message
}

set_error_handler("errorHandler");

$referer = $_REQUEST['referer'];
$username = $_POST['username'];
$password = $_POST['password'];

if ( $username != '' && $password != '' ) {
	
		$db = dbconnect();
		$sql = "SELECT count(*) FROM login".
				" WHERE username='$username'" .
				" AND password='$password'";
		$rowct = $db->getOne($sql);
		if ( $rowct > 0 ) {
			$_SESSION['user'] = $username;
			header( "Location:" . $referer );
			exit;
		} else {
			$error = "Invalid username or password";
		}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Anime Setup - Login</title>
<link rel="stylesheet" type="text/css" href="../site.css"/>
<script type="text/javascript" src="../site.js"></script>
</head>
<body style="font-family: arial, helvetica, sans-serif" onload="javascript:grabFocus('username')">
<h1>Anime Setup</h1>
<form action="login.php" method="post">
<input name="referer" type="hidden" value="<?php echo $referer?>">
Username: <input name="username" type="text" id="username">
Password: <input name="password" type="password">
<input type="submit" name="submit" value="Login">
</form>
<?php
	if ( $error != "" ) {
		echo "<p style=\"color:red\">" . $error . "</p>";
	}
?>		
</body>
</html>